package com.boarsoft.boar.soagov.dir;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.dir.DirExBiz;
import com.boarsoft.boar.entity.DirInfo;
import com.boarsoft.boar.soagov.com.ComBiz;
import com.boarsoft.boar.soagov.face.FaceBiz;
import com.boarsoft.boar.soagov.face.FaceParamBiz;
import com.boarsoft.boar.soagov.face.ObjFacesBiz;
import com.boarsoft.boar.soagov.svc.SvcBiz;

@Component("dirExBiz")
public class DirExBizImpl implements DirExBiz {
	@Autowired
	protected FaceBiz faceBiz;
	@Autowired
	protected FaceParamBiz faceParamBiz;
	@Autowired
	protected ComBiz comBiz;
	@Autowired
	protected ObjFacesBiz comFacesBiz;
	@Autowired
	protected SvcBiz svcBiz;

	@Override
	@Transactional
	public String copy(short type, String id, String to, String newId) throws Exception {
		switch (type) {
		case DirInfo.TYPE_FACE:
			return faceBiz.copy(id, to, newId);
		case DirInfo.TYPE_COM:
			return comBiz.copy(id, to, newId);
		case DirInfo.TYPE_SVC:
			return svcBiz.copy(id, to, newId);
		case DirInfo.TYPE_FLOW:
			// return flowBiz.copy(id, to, newId);
			return newId;
		default:
			throw new Exception("Unknow dir type ".concat(String.valueOf(type)));
		}
	}

	@Override
	@Transactional
	public boolean move(short type, String id, String to) throws Exception {
		switch (type) {
		case DirInfo.TYPE_FACE:
			return faceBiz.move(id, to);
		case DirInfo.TYPE_COM:
			return comBiz.move(id, to);
		case DirInfo.TYPE_SVC:
			return svcBiz.move(id, to);
		case DirInfo.TYPE_FLOW:
			return true;
		default:
			throw new Exception("Unknow dir type ".concat(String.valueOf(type)));
		}
	}

	@Override
	@Transactional
	public void delete(int type, String id) throws Exception {
		switch (type) {
		case DirInfo.TYPE_FACE:
			faceBiz.delete(id);
			return;
		case DirInfo.TYPE_COM:
			comBiz.delete(id);
			return;
		case DirInfo.TYPE_SVC:
			svcBiz.delete(id);
			return;
		case DirInfo.TYPE_FLOW:
			return;
		}
	}
}